package com.movecar.ui;

import BLLocationCallbacker.PopWindowsCallbacker;
import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.LinearLayout.LayoutParams;
import android.widget.PopupWindow;

import com.movecar.R;

/**
 * 主页popup列表
 * 
 * @author Zhao.JQ
 *
 */
public class HomePopWindow extends PopupWindow implements OnClickListener {
	private Button button_ground, button_my_ground, button_friends_ground;

	private int resId;
	private Context context;
	private LayoutInflater inflater;
	public View defaultView;
	public PopWindowsCallbacker callBack;
	private int newTipIndex1, newTipIndex2;

	public HomePopWindow(Context context, int resId, PopWindowsCallbacker callBack, int newTipIndex1, int newTipIndex2) {
		super(context);
		this.context = context;
		this.resId = resId;
		this.callBack = callBack;
		this.newTipIndex1 = newTipIndex1;
		this.newTipIndex2 = newTipIndex2;
		initPopupWindow();
	}

	public void initPopupWindow() {
		inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		defaultView = inflater.inflate(this.resId, null);
		defaultView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
		setContentView(defaultView);
		button_ground = (Button) defaultView.findViewById(R.id.button_ground);
		button_my_ground = (Button) defaultView.findViewById(R.id.button_my_ground);
		button_friends_ground = (Button) defaultView.findViewById(R.id.button_friends_ground);
		button_ground.setOnClickListener(this);
		button_my_ground.setOnClickListener(this);
		button_friends_ground.setOnClickListener(this);
		setWidth(LayoutParams.MATCH_PARENT);
		setHeight(LayoutParams.WRAP_CONTENT);
		setBackgroundDrawable(new ColorDrawable(android.R.color.transparent));
		setFocusable(true);
		setOutsideTouchable(true);

	}

	/**
	 * 
	 * @return pop的View
	 */
	public View getDefaultView() {
		return defaultView;
	}

	@Override
	public void onClick(View v) {
		// SharedPreferences sharedPreferences =
		// this.context.getSharedPreferences("new_message",
		// Context.MODE_PRIVATE);
		// Editor editor = sharedPreferences.edit();// 获取编辑器
		switch (v.getId()) {

		case R.id.button_ground:

			callBack.onClick("浮云广场");
			break;

		case R.id.button_my_ground:

			callBack.onClick("我的分享");

			break;
		case R.id.button_friends_ground:
			callBack.onClick("好友分享");

			// editor.clear();
			// editor.commit();// 提交修改
			break;

		default:
			break;

		}
		if (isShowing()) {
			dismiss();
		}
	}

}
